% Copyright 2007 by 
% Philippe Dreuw <dreuw@cs.rwth-aachen.de> and 
% Thomas Deselaers <deselaers@cs.rwth-aachen.de>
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
%
% ChangeLog:
%
% 1.07 - bugfixed custom size handling, portrait or landscape settings are ignored now
% 1.06 - added the type1cm package for scalable math fonts
% 1.05 - added version check for xkeyval package
% 1.04 - added custom size handling
% 1.03 - improved predefined size handling
% 1.02 - minor bugfixes
% 1.01 - bugfixed size handling
% 1.00 - first beamerposter release
%
\def\beamerposter@version{1.07}
\def\beamerposter@date{2008/03/11}
\def\beamerposter@msg{beamerposter: latex-beamer poster extension}
\typeout{Package: \beamerposter@date. v.\beamerposter@version. \beamerposter@msg} 

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{beamerposter}[\beamerposter@date. v.\beamerposter@version. \beamerposter@msg]
\RequirePackage{xkeyval}[2006/11/18]
\RequirePackage{type1cm} %% get it from ftp://cam.ctan.org/tex-archive/macros/latex/contrib/type1cm.zip

\newif\ifportrait
\newif\ifcustomsize
\newif\ifdebug

\DeclareOptionX{size}[a0]{
  \typeout{beamerposter: checking size input, please wait.}
  \XKV@cc*+[\val\nr]{#1}{a0b,a0,a1,a2,a3,a4,custom}{%
    \typeout{beamerposter: the input \val\ \nr\ was correct, we proceed.}
    \ifcase\nr\relax
    %a0b
    \setlength{\paperwidth}{119cm}
    \setlength{\paperheight}{88cm}
    \setlength{\textwidth}{116cm}
    \setlength{\textheight}{88cm}
    \or
    %a0
    \setlength{\paperwidth}{118.82cm}
    \setlength{\paperheight}{83.96cm}
    \setlength{\textwidth}{117.82cm}
    \setlength{\textheight}{82.96cm}
    \or
    %a1
    \setlength{\paperwidth}{83.96cm}
    \setlength{\paperheight}{59.4cm}
    \setlength{\textwidth}{82.96cm}
    \setlength{\textheight}{58.4cm}
    \or
    %a2
    \setlength{\paperwidth}{59.4cm}
    \setlength{\paperheight}{41.98cm}
    \setlength{\textwidth}{58.4cm}
    \setlength{\textheight}{40.98cm}
    \or
    %a3
    \setlength{\paperwidth}{41.98cm}
    \setlength{\paperheight}{29.7cm}
    \setlength{\textwidth}{40.98cm}
    \setlength{\textheight}{28.7cm}
    \or
    %a4
    \setlength{\paperwidth}{29.7cm}
    \setlength{\paperheight}{21.0cm}
    \setlength{\textwidth}{28.7cm}
    \setlength{\textheight}{20.0cm}
    \or
    \customsizetrue
    \fi    
  }{%
    \PackageWarning{beamerposter}{the input \val\ was incorrect and was ignored.}
  }%
  \typeout{beamerposter: finished size input check.}
}
\DeclareOptionX{orientation}[portrait]{
  \typeout{beamerposter: checking orientation input, please wait.}
  \XKV@cc*+[\val\nr]{#1}{portrait,landscape}{%
    \typeout{beamerposter: the input \val\ \nr\ was correct, we proceed.}
    \ifcase\nr\relax
    \portraittrue
    \or
    \portraitfalse
    \fi    
  }{%
    \PackageWarning{beamerposter}{the input \val\ was incorrect and was ignored.}
  }%
  \typeout{beamerposter: finished orientation check.}
}
\DeclareOptionX{scale}[1.0]{\edef\myfontscale{#1}\typeout{beamerposter: myfontscale=\myfontscale}}
\DeclareOptionX{width}{\edef\customwidth{#1}\typeout{beamerposter: custom poster width=\customwidth}}
\DeclareOptionX{height}{\edef\customheight{#1}\typeout{beamerposter: custom poster height=\customheight}}
\DeclareOptionX{debug}{\typeout{beamerposter: enabled debug mode}\debugtrue}
\DeclareOptionX*{\PackageWarning{beamerposter}{Unknown option ignored: \CurrentOption}}
%\DeclareOptionX*{\PassOptionsToClass{\CurrentOption}{beamer}}
\ExecuteOptionsX{size=a0,scale=1.0}
\ProcessOptionsX\relax

\ifdebug
  \RequirePackage[debug]{fp}
\else
  \RequirePackage{fp}
\fi

%% swap sizes for portrait orientation
\ifportrait
  \newdimen\tmp
  \setlength{\tmp}{\paperwidth}
  \setlength{\paperwidth}{\paperheight}
  \setlength{\paperheight}{\tmp}
  \setlength{\tmp}{\textwidth}
  \setlength{\textwidth}{\textheight}
  \setlength{\textheight}{\tmp}
\else\relax
\fi

%% overwrite dimensions if custom size
\ifcustomsize
  \setlength{\paperwidth}{\customwidth cm}
  \setlength{\paperheight}{\customheight cm}
  \FPupn{\resulttextwidth}{1 customwidth  -}
  \FPupn{\resulttextheight}{1 customheight -}
  \setlength{\textwidth}{\resulttextwidth cm}
  \setlength{\textheight}{\resulttextheight cm}
\fi

%% Setting proper dimensions for a DIN A0 printer
\setlength{\headheight}{0 cm}
\setlength{\headsep}{0 cm}
\setlength{\topmargin}{-12.7 mm}     % -1in +1.47cm
\setlength{\oddsidemargin}{-25.4 mm} % -1in +0.4cm

%% For the page layout
\ifdebug
\typeout{beamerposter: paperwidth=\the\paperwidth, paperheight=\the\paperheight}
\typeout{beamerposter: textwidth=\the\textwidth, textwidth=\the\textheight}
\fi
\geometry{
  paperwidth=\the\paperwidth,
  paperheight=\the\paperheight,
  hmargin=1cm,%
  vmargin=0cm,%
  head=0.5cm, % 
  headsep=0pt,%
  foot=0.5cm  % 
}

%% scalable vector fonts
\edef\fontSizeX{12}\edef\fontSizeY{14}
\FPupn{\resulttinyX}{myfontscale fontSizeX * 2 round}
\FPupn{\resulttinyY}{myfontscale fontSizeY * 2 round}
\renewcommand*{\tiny}{\fontsize{\resulttinyX}{\resulttinyY}\selectfont}

\edef\fontSizeX{14.4}\edef\fontSizeY{18}   
\FPupn{\resultscriptsizeX}{myfontscale fontSizeX * 2 round}
\FPupn{\resultscriptsizeY}{myfontscale fontSizeY * 2 round}
\renewcommand*{\scriptsize}{\fontsize{\resultscriptsizeX}{\resultscriptsizeY}\selectfont}

\edef\fontSizeX{17.28}\edef\fontSizeY{22}
\FPupn{\resultfootnotesizeX}{myfontscale fontSizeX * 2 round}
\FPupn{\resultfootnotesizeY}{myfontscale fontSizeY * 2 round}
\renewcommand*{\footnotesize}{\fontsize{\resultfootnotesizeX}{\resultfootnotesizeY}\selectfont}

\edef\fontSizeX{20.74}\edef\fontSizeY{25}
\FPupn{\resultsmallX}{myfontscale fontSizeX * 2 round}
\FPupn{\resultsmallY}{myfontscale fontSizeY * 2 round}
\renewcommand*{\small}{\fontsize{\resultsmallX}{\resultsmallY}\selectfont}

\edef\fontSizeX{24.88}\edef\fontSizeY{30}
\FPupn{\resultnormalsizeX}{myfontscale fontSizeX * 2 round}
\FPupn{\resultnormalsizeY}{myfontscale fontSizeY * 2 round}
\renewcommand*{\normalsize}{\fontsize{\resultnormalsizeX}{\resultnormalsizeY}\selectfont}

\edef\fontSizeX{29.86}\edef\fontSizeY{37}
\FPupn{\resultlargeX}{myfontscale fontSizeX * 2 round}
\FPupn{\resultlargeY}{myfontscale fontSizeY * 2 round}
\renewcommand*{\large}{\fontsize{\resultlargeX}{\resultlargeY}\selectfont}

\edef\fontSizeX{35.83}\edef\fontSizeY{45}
\FPupn{\resultLargeX}{myfontscale fontSizeX * 2 round}
\FPupn{\resultLargeY}{myfontscale fontSizeY * 2 round}
\renewcommand*{\Large}{\fontsize{\resultLargeX}{\resultLargeY}\selectfont}

\edef\fontSizeX{43}\edef\fontSizeY{54}
\FPupn{\resultLARGEX}{myfontscale fontSizeX * 2 round}
\FPupn{\resultLARGEY}{myfontscale fontSizeY * 2 round}
\renewcommand*{\LARGE}{\fontsize{\resultLARGEX}{\resultLARGEY}\selectfont}

\edef\fontSizeX{51.6}\edef\fontSizeY{64}
\FPupn{\resulthugeX}{myfontscale fontSizeX * 2 round}
\FPupn{\resulthugeY}{myfontscale fontSizeY * 2 round}
\renewcommand*{\huge}{\fontsize{\resulthugeX}{\resulthugeY}\selectfont}

\edef\fontSizeX{61.92}\edef\fontSizeY{77}
\FPupn{\resultHugeX}{myfontscale fontSizeX * 2 round}
\FPupn{\resultHugeY}{myfontscale fontSizeY * 2 round}
\renewcommand*{\Huge}{\fontsize{\resultHugeX}{\resultHugeY}\selectfont}

\edef\fontSizeX{74.3}\edef\fontSizeY{93}
\FPupn{\resultveryHugeX}{myfontscale fontSizeX * 2 round}
\FPupn{\resultveryHugeY}{myfontscale fontSizeY * 2 round}
\newcommand*{\veryHuge}{\fontsize{\resultveryHugeX}{\resultveryHugeY}\selectfont}

\edef\fontSizeX{89.16}\edef\fontSizeY{112}
\FPupn{\resultVeryHugeX}{myfontscale fontSizeX * 2 round}
\FPupn{\resultVeryHugeY}{myfontscale fontSizeY * 2 round}
\newcommand*{\VeryHuge}{\fontsize{\resultVeryHugeX}{\resultVeryHugeY}\selectfont}

\edef\fontSizeX{107}\edef\fontSizeY{134}
\FPupn{\resultVERYHugeX}{myfontscale fontSizeX * 2 round}
\FPupn{\resultVERYHugeY}{myfontscale fontSizeY * 2 round}
\newcommand*{\VERYHuge}{\fontsize{\resultVERYHugeX}{\resultVERYHugeY}\selectfont}

% set the normalfont (default)
\renewcommand*{\normalfont}{\normalsize}
